package club.gskj.gulimall.order.web;

import club.gskj.gulimall.order.config.AlipayTemplate;
import club.gskj.gulimall.order.service.OrderService;
import club.gskj.gulimall.order.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class PayOrderController {

    @Autowired
    private AlipayTemplate alipayTemplate;

    @Autowired
    private OrderService orderService;

    /***
     *  调用支付宝第三方支付, 支付成功后让浏览器显示用户订单列表
     * @param orderSn 订单号
     */
    @ResponseBody
    @GetMapping(value = "/payOrder", produces = "text/html")
    public String payOrder(@RequestParam("orderSn") String orderSn) throws Exception {
        PayVo payVo = orderService.getOrderPayInfoByOrderSn(orderSn);
        String payHtml = alipayTemplate.pay(payVo);
        /**
         * <form name="punchout_form" method="post" action="https://openapi.alipaydev.com/gateway.do?charset=utf-8&method=alipay.trade.page.pay&sign=KfwEZ9EmgK3uZdmYoTppg5uSTPXk5zU7Yu%2Fq%2BRw2%2Bren3atuyvbQBxAS9dmLXKDaKgNuEmnWeHyF5GvCEsFWK2EglKPkRxIoeRbLo2Xw44QxL6nH9Hq9jkc7MU%2FUFqpqpTksZN7O%2BQCsbPa15b%2FhKB%2Bdv%2FmLLgZds5EU0UPPmrlW6VLTaEgDOYmpIcE9ACWfjAYiTz3YjkEgqccJ%2BrmTbccO5gQMdCc1K5ov9GBtQEQohp0r9zrxi2DCANn9Idakjhx%2Bd8EsZc2vyvSa2A9%2FAJIOMfoxeUx4bq2VHfVGm3qmEvMksLfIpJvnvPKp202ygRypUwCgEVwQQqE74H5kOQ%3D%3D&return_url=http%3A%2F%2F%2Falipay.trade.page.pay-JAVA-UTF-8%2Freturn_url.jsp&notify_url=http%3A%2F%2F%2Falipay.trade.page.pay-JAVA-UTF-8%2Fnotify_url.jsp&version=1.0&app_id=2016102300744568&sign_type=RSA2&timestamp=2021-04-12+23%3A08%3A26&alipay_sdk=alipay-sdk-java-dynamicVersionNo&format=json">
         * <input type="hidden" name="biz_content" value="{&quot;out_trade_no&quot;:&quot;202104122308091581381625189372022785&quot;,&quot;total_amount&quot;:&quot;56995.00&quot;,&quot;subject&quot;:&quot;华为Mate30EPro/Mate30pro可选 5G版 手机  罗蓝紫 8+256&quot;,&quot;body&quot;:&quot;颜色:罗蓝紫;版本:8+256&quot;,&quot;product_code&quot;:&quot;FAST_INSTANT_TRADE_PAY&quot;}">
         * <input type="submit" value="立即支付" style="display:none" >
         * </form>
         * <script>document.forms[0].submit();</script>
         */
        return payHtml;
    }
}
